package kr.or.javacafe.intro.controller;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import kr.or.javacafe.intro.domain.YearHistory;
import kr.or.javacafe.manage.bo.*;
import kr.or.javacafe.manage.domain.*;
import kr.or.javacafe.member.bo.MemberBO;
import kr.or.javacafe.member.domain.User;

@Controller
@RequestMapping("/intro")
public class IntroController {
	
	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(IntroController.class);
		
	@Autowired
	ManageBO manageBO;
	
	@Autowired
	MemberBO memberBO;
	
	
	
	@RequestMapping("/welcome")
	public String welcome(Model model) {
		model.addAttribute("information", manageBO.getWelcome());		
		return "/intro/welcome";
	}

	@RequestMapping("/people")
	public String people(Model model) {
		User param = new User();
		param.setRoleGrpId("G3");

		int intListCount = memberBO.getUserListCount(param);

		param.setStartNum(0);
		param.setEndNum(100);
		
		List<User> objList = memberBO.getUserList(param);
		
		model.addAttribute("objList", objList);
		
		return "/intro/people";
	}

	@RequestMapping("/history")
	public String history(Model model) {
		List objList = new ArrayList();
		
		Information objHistory = manageBO.getHistory();
		String[] arrTemp = objHistory.getContents().split("&lt;@YEAR_START@&gt;");
		for (String strTemp : arrTemp) {
			if (strTemp.contains("&lt;@YEAR_END@&gt;")) {
				String[] arrText = strTemp.split("&lt;@YEAR_END@&gt;");
				
				YearHistory objHist = new YearHistory();
				objHist.setYear(arrText[0]);
				objHist.setText(arrText[1]);
				
				objList.add(objHist);
			}
		}
		
		model.addAttribute("objList", objList);	

		return "/intro/history";
	}

	@RequestMapping("/regulation")
	public String regulation(Model model) {
		model.addAttribute("information", manageBO.getRegulation());
		return "/intro/regulation";
	}

	@RequestMapping("/site")
	public String site() {
		return "/intro/site";
	}

	
}